<?php
	require_once "includes/pagination.php";
	require_once 'includes/class.phpmailer.php';
	$itemPerPage=50;
	if($_SESSION['user_id_sess']=="") {
		echo "<script type='text/javascript'> window.location='index.php?signin&url=mylist'; </script>";
	}
	$userId = $_SESSION['user_id_sess'];
?>
<div id='panel'>

<div class="fulldiv" style="width:700px;">

<div class="fulldiv" style="margin:10px 0px 0px 0px;">
       <div style="float:left; margin:0px 10px 0px 10px; padding-top:8px;"><strong class="orangehead">Commission I Owe</strong></div>
       <div class="greyarrowsml" onclick="show_hide_s_boxes('comm_pay')" id="arrow_comm_pay">&nbsp;</div>
       <?php
       $sqlSelItem_1="SELECT o.order_id,u.user_id,p.product_id,ADDDATE(o.order_date, INTERVAL 15 DAY) as dateFrom,ADDDATE(o.order_date, INTERVAL 30 DAY) as dateTo  FROM tbl_orders o left join tbl_users u on o.order_comm_to_user_id=u.user_id left join tbl_items i on i.item_id=o.item_id left join tbl_product p on p.product_id=i.product_id  where order_comm_by_user_id='$userId' AND order_comm_to_user_id !='$userId' AND is_comm_paid='0' ORDER BY order_id DESC";
       $myquery = mysql_query($sqlSelItem_1) or die(mysql_error());
       $cnt_myquery =  mysql_num_rows($myquery);
       if($cnt_myquery!=0) {
       ?>
	<div style="float:left; width:150px; padding:5px 0px 0px 15px; color:#6B6767; font-size:14px;" id="count_box_comm_pay"><?php echo $cnt_myquery." NEW";?></div>
       <?php
       }
       $fright= 'style="width:48%; margin-top:13px; float:right;"';
       if($_SESSION['user_type_sess']!=3) { $fright = 'style="width:48%; margin-top:13px;"'; }
       ?>
       <div class="fulldiv" <?php echo $fright?>>
	<div class="star" style="float: right;" id="star_comm_pay">&nbsp;</div>
	<a href="javascript:void(0)" class="bluelink" style="float: right;" onclick="show_more_info2()" id="more_info_comm_pay">more info</a>
       </div>
       <?php
       if($_SESSION['user_type_sess']!=3) {
       ?>
       <div class="greytab_out" id="other1_comm_pay">
		
		<span style="float:left; margin:0px 0px 10px 0px;">&nbsp;</span>		
		<div class="greytab_left">&nbsp;</div>
		<div class="greytab_repeat" style="cursor:pointer;" onclick="window.location='https://www.amazon.com/gp/css/homepage.html?ie=UTF8&ref_=topnav_ya'">Refund Transaction</div>
		<div class="greytab_right">&nbsp;</div>
	</div>
       <?php
       }
       ?>
</div>
<script>
function show_more_info2()
{
  var ntop = ( $(window).height() - $('#more_info2').height() ) / 2+$(window).scrollTop();
  var nleft = ( $(window).width() - $('#more_info2').width() ) / 2+$(window).scrollLeft();

  $('#more_info2').css({'left': nleft, 'top':ntop});
  $('#more_info2').fadeIn('slow');
}
function show_contact_user_box(sold_by_id,product_id,transaction_ID)
{
	//href='sendowner.php?ownerid=".$sold_by_id."&jobid=".$product_id."&type=M'
	document.getElementById('txtSub2').value='Transaction #'+transaction_ID;
	var ntop = (( $(window).height() - $('#contact_user_'+product_id).height()) / 2+$(window).scrollTop()) - 100;
	var nleft = ( $(window).width() - $('#contact_user_'+product_id).width()) / 2+$(window).scrollLeft();

	$('#recieverid').val(sold_by_id);
	$('#jobid').val(product_id);
	$('#type').val('M');
	//$('#productname').val(product_name);
	$('#contact_user_box').css({'left': '', 'top':ntop}).fadeIn('slow');
	
}
function send_message()
{
	var recieverid 	= $('#recieverid').val();
	var jobid 	= $('#jobid').val();
	var type 	= $('#type').val();
	var txtSub 	= $('#txtSub').val();
	var txtQuery 	= $('#txtQuery').val();
	var productname	= $('#productname').val();
	var url = "<?php echo $base_url;?>sendowner.php";
	$.post(url,
	{ 'recieverid': recieverid,'jobid':jobid, 'type':type, 'txtSub':txtSub, 'txtQuery':txtQuery},
		function(data)
		{
			
			if(trim(data)=='ok')
			{
				
				$('#msgbox').html('<h1 style="float:left; width:100%; text-align:center;">Message sent successfully</h1><div align="center" style="float:left; width:98%; padding:5px;"><input type="button" onclick="$(\'#contact_user_box\').hide();" name="" value="Close" class="refer_btn" style="margin:0px; height:30px;" /></div>');
			}
			else
			{
				$('#msgbox').html('<h1 style="float:left; width:100%; text-align:center;">Message not sent.</h1><div align="center" style="float:left; width:98%; padding:5px;"><input type="button" onclick="$(\'#contact_user_box\').hide();" name="" value="Close" class="refer_btn" style="margin:0px; height:30px;" /></div>');
			}
		},
	'html'
	);
}
</script>
<div style=" display: none; width: 400px; font-weight:bold; padding:10px; background-color:#cccccc; opacity:0.9;" class="user_popup" id="more_info2">
  <span style="float:left; width:100%; text-align:right; margin-bottom:5px;"><label style="cursor:pointer;" onclick="$('#more_info2').fadeOut('slow');">x</label></span>
  <span style="float:left; width:100%; margin-bottom:10px;" id="desc_info">Commission I Owe shows sellers who have sold your product, how much you owe, and when you should pay.</span>
</div>
<div id="comm_pay">
<div class="fullbox_top">&nbsp;</div>
<div class="fullbox_repeat">

<table width="98%" border="0">
  <tr>
	<td>
		<div style="float: left; width: 660px; border-bottom:2px solid #ccc;">
			<div class="cell_head" style="width: 100px;">Product</div>
			<div class="cell_head" style="width: 80px;">Sold By</div>
			<div class="cell_head" style="width: 93px;">Transaction #</div>
			<div class="cell_head" style="width: 72px; text-align:center;">Transaction Date</div>
			<div class="cell_head" style="width: 63px; text-align:center;">Amt Owed</div>
			<div class="cell_head" style="width: 130px;">Comm. Pay Period</div>
			<div class="cell_head" style="width: 65px;">&nbsp;</div>
		</div>
		
		<div style="max-height:160px; overflow-y:auto; overflow-x:hidden; width:660px; float:left;">
			
			<?php
			$sqlSelItem="SELECT o.*,u.*,p.product_name,p.product_id,ADDDATE(o.order_date, INTERVAL 15 DAY) as dateFrom,ADDDATE(o.order_date, INTERVAL 30 DAY) as dateTo  FROM tbl_orders o left join tbl_users u on o.order_comm_to_user_id=u.user_id left join tbl_items i on i.item_id=o.item_id left join tbl_product p on p.product_id=i.product_id  where order_comm_by_user_id='$userId' AND order_comm_to_user_id !='$userId'  ORDER BY order_id DESC";
			//echo $sqlSelItem;
			$rstSelItem=mysql_query(getPagingQuery($sqlSelItem,$itemPerPage));				
			$noSelItem=mysql_num_rows($rstSelItem);
			
			if($noSelItem==0)
			{
				echo "<div style='border-top:1px solid #CCCCCC;'> </div><br>";
				echo "<p style='padding:5px;'>No Commission found on your list...</p><br>";
				echo "<div style='border-top:1px solid #CCCCCC;'> </div><br>";
			}
					
			$r=1;
			while($rowSelItem=mysql_fetch_array($rstSelItem))
			{						   
				$transaction_ID = substr($rowSelItem['transaction_ID'],0,10);
				$product_name=$rowSelItem['product_name'];
				if($product_name==NULL || $product_name=='')
				$product_name = 'No Product';
				$username=$rowSelItem['username'];
				if($username=='')
				$username='&nbsp;';
				$transaction_ID=$rowSelItem['transaction_comm'];
				$order_date=$rowSelItem['order_date'];
				$order_comm=$rowSelItem['order_comm'];
				$timestamp=strtotime($order_date);
				$order_date=date("m/d/Y",$timestamp);
				     
				$dateFrom =strtotime($rowSelItem['dateFrom']);
				$dateTo =strtotime($rowSelItem['dateTo']);
					   
				$dateFrom =date("m/d/Y",$dateFrom);
				$dateTo =date("m/d/Y",$dateTo);
				$com_user=$rowSelItem['order_comm_by_user_id'];
				$product_id=$rowSelItem['product_id'];	
				if($rowSelItem['is_comm_paid']=='0')
				{	   
					$editItem="<a href='amazon_comm.php?order_id=".$rowSelItem['order_id']."' class='yellow_btn' style='text-decoration:none;' >Pay Now</a>";
					//$editItem="<a href='sendowner.php?ownerid=".$rowSelItem['order_comm_to_user_id']."&jobid=".$rowSelItem['product_id']."&type=M' target='_blank'>Contact User</a>";						 
				}
				else
				{
					//$editItem="<a href='sendowner.php?ownerid=".$rowSelItem['order_comm_to_user_id']."&jobid=".$rowSelItem['product_id']."&type=M' target='_blank' class='yellow_btn' style='text-decoration:none; height: 29px;margin: 0px 0px 5px 0px; padding: 5px 5px 0px 5px;'>Contact User</a>";
					$editItem="<a href='javascript:void(0);' onclick='show_contact_user_box($com_user,$product_id,\"$transaction_ID\")' id='contact_user_$product_id' class='yellow_btn' style='padding:5px 5px 0px 5px; height:29px; margin:0px 0px 5px 0px;'>Contact User</a>";		
				}
				if($timeLeft < 0)
				{
					$timeLeft = "<font color='red'>Listing Expired</font>";
				}
					
				
				?>
				<div style="float:left; width:659px; border-bottom:1px solid #ccc; margin:3px 0px 3px;">
					<div class="cell_row" style="width: 100px;"><?php echo wordFormater($product_name,10);?></div>
					<div class="cell_row" style="width: 83px;"><?php echo $username;?></div>
					<div class="cell_row" style="width: 93px;" title="<?php echo $rowSelItem['transaction_ID'];?>"><?php echo $transaction_ID;?></div>
					<div class="cell_row" style="width: 75px; text-align:center;"><?php echo $order_date;?></div>
					<div class="cell_row" style="width: 63px; text-align:center;">$<?php echo $order_comm;?></div>
					<div class="cell_row" style="width: 130px; text-align:center;"><?php echo $dateFrom." to ".$dateTo;?></div>
					<div class="cell_row" style="width: 60px;"><?php echo $editItem;?></div>
				</div>
				<?php
				$r++;
			}
			?>	
			
		</div>
		
	</td>
</tr>
<tr>
	<td><div align="center"><?php
		   $link="mySwapen";
		   echo $disp=getPagingLink($sqlSelItem,$itemPerPage,$link);
	 ?></div></td>
</tr>

</table>

</div>
<div class="fullbox_bot">&nbsp;</div>
</div>
<hr style="float:left; width:500px; display:none;" id="hr_line_comm_pay" />
</div>
</div>
<div class="popup_box" style="display:none; position:absolute; background:#FFFFFF;" id="contact_user_box"> 
  <div class="popup_box_in" style="height:200px;">
      <div style="float: left; margin: 0 30px; padding: 5px; text-align: left; width: 85%;" id="msgbox">
	   
	<table cellspacing="3" cellpadding="5" border="0" width="100%" class="boldGreyNotes">
		<tbody>
			<tr>
				<td width="16%">Subject</td>
				<td width="24%"><!--<input type="text" id="txtSub" name="txtSub" value="Transaction Referenced"/>--><input type="text" id="txtSub2" name="txtSub2"/></td>
				<td width="12%">&nbsp;</td>
				<td width="48%">&nbsp;</td>
			</tr>
			<tr>
				<td>Your Message </td>
				<td colspan="3"><textarea id="txtQuery" rows="5" cols="40" name="txtQuery"></textarea></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td colspan="3">
					<input type="button" value="Send Message" name="submit" class="refer_btn" onclick="send_message()" />
					<input type="button" onclick="$('#contact_user_box').hide();" value="Close" name="Submit2" class="refer_btn" />
					<input type="hidden" value="" name="recieverid" id="recieverid" />
					<input type="hidden" value="" name="productname">
					<input type="hidden" value="" name="jobid" id="jobid" />
					<input type="hidden" name="type" id="type" />
				</td>
			</tr>
	     </tbody>
	</table>
      </div>
      
  </div>
</div>